//mVGmWYtHtXTtGGPRWYLmVWNWmf0r83dA



//鼠标点击地图
function f点击获取坐标(map, callback) {
	var geoc = new BMapGL.Geocoder();
	map.addEventListener('click', function(e) {
		var pt = e.latlng;
		console.log(pt)
		geoc.getLocation(pt, function(rs) {
			var addComp = rs.addressComponents;
			callback && callback(addComp);
			console.log(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp
				.street + ", " + addComp.streetNumber);
		})
	})
}

function f定位转描述(map, 经度, 维度) {
	map.centerAndZoom(new BMapGL.Point(经度, 维度), 11);
	// 创建地理编码实例      
	var myGeo = new BMapGL.Geocoder();
	// 根据坐标得到地址描述    
	myGeo.getLocation(new BMapGL.Point(经度, 维度), function(result) {
		if (result) {
			alert(result.address);
		}
	});
}

function f描述转定位(map, 城市, 地址) {
	//创建地址解析器实例
	var myGeo = new BMapGL.Geocoder();
	// 将地址解析结果显示在地图上，并调整地图视野
	myGeo.getPoint(地址, function(point) {
		if (point) {
			map.centerAndZoom(point, 16);
			map.addOverlay(new BMapGL.Marker(point, {
				title: 地址
			}))
		} else {
			alert('您选择的地址没有解析到结果！');
		}
	}, 城市)
}
/**
 * p1 格式 116.301934,39.977552
 */
function f驾驶路线(map, dw1, dw2) {
	var p1 = new BMapGL.Point(dw1[0], dw1[1]);
	var p2 = new BMapGL.Point(dw2[0], dw2[1]);
	var driving = new BMapGL.DrivingRoute(map, {
		renderOptions: {
			map: map,
			autoViewport: true
		}
	});
	driving.search(p1, p2);
}

function f公交路线(map, dw1, dw2) {
	var output = '';
	var transit = new BMapGL.TransitRoute(map, {
		renderOptions: {
			map: map
		},
		onSearchComplete: function(results) {
			if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
				return;
			}
			var plan = results.getPlan(0);
			output += '总时长：' + plan.getDuration(true); //获取时间
			output += '总路程：' + plan.getDistance(true); //获取距离
			$('#result').css('display', 'block');
			$('#result').html(output);
		},
	});
	var p1 = new BMapGL.Point(dw1[0], dw1[1]);
	var p2 = new BMapGL.Point(dw2[0], dw2[1]);
	transit.search(p1, p2);
}

function f步行路线(map, p1, p2) {

	var walking = new BMapGL.WalkingRoute(map, {
		renderOptions: {
			map: map,
			autoViewport: true
		}
	});
	walking.search(p1, p2);
}

function g当前城市(map) {
	function myFun(result) {
		var cityName = result.name;
		map.setCenter(cityName);
		alert("当前定位城市:" + cityName);
	}
	var myCity = new BMapGL.LocalCity();
	myCity.get(myFun);
}

function g当前坐标(map, 开启辅助定位 = true) {
	var geolocation = new BMapGL.Geolocation();
	// 开启SDK辅助定位
	if (开启辅助定位)
		geolocation.enableSDKLocation();
	geolocation.getCurrentPosition(function(r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			var mk = new BMap.Marker(r.point);
			map.addOverlay(mk);
			map.panTo(r.point);
			alert('您的位置：' + r.point.lng + ',' + r.point.lat);
		} else {
			alert('failed' + this.getStatus());
		}
	});
}
